package com.mcptt.config.ue.initial.sub.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.comm.CheckData;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.ue.initial.CallTimer;

public class Timers {
	public static final String Name = "Timers";
	private static final String Name_T100 = "T100";
	private static final String Name_T101 = "T101";
	private static final String Name_T102 = "T102";
	private static final String Name_T103 = "T103";
	private static final String Name_T104 = "T104";
	private static final String Name_T132 = "T132";
	
	private int t100 = 300;//ms
	private int t101 = 300;//ms
	private int t103 = 300;//ms
	private int t104 = 300;//ms
	private int t132 = 2000;//ms
	
	

	
	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_T100))
			{
				String value = subElem.getText();
				t100 = CheckData.parseInt(value);
			}
			else if(name.equals(Name_T101))
			{
				String value = subElem.getText();
				t101 = CheckData.parseInt(value);
			}
//			else if(name.equals(Name_T102))
//			{
//				String value = subElem.getText();
//				t102 = CheckData.parseInt(value);
//			}
			else if(name.equals(Name_T103))
			{
				String value = subElem.getText();
				t103 = CheckData.parseInt(value);
			}
			else if(name.equals(Name_T104))
			{
				String value = subElem.getText();
				t104 = CheckData.parseInt(value);
			}
			else if(name.equals(Name_T132))
			{
				String value = subElem.getText();
				t132 = CheckData.parseInt(value);
			}
		}  
	}
	
	public CallTimer toCallTimer()
	{
		return new CallTimer(t100, t101, t103, t104, t132);
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_T100).append(">");
		strBuf.append(t100);
		strBuf.append("</").append(Name_T100).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_T101).append(">");
		strBuf.append(t101);
		strBuf.append("</").append(Name_T101).append(">").append("\r\n");
//		strBuf.append("    ").append("<").append(Name_T102).append(">");
//		strBuf.append(t102);
//		strBuf.append("</").append(Name_T102).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_T103).append(">");
		strBuf.append(t103);
		strBuf.append("</").append(Name_T103).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_T104).append(">");
		strBuf.append(t104);
		strBuf.append("</").append(Name_T104).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_T132).append(">");
		strBuf.append(t132);
		strBuf.append("</").append(Name_T132).append(">").append("\r\n");
		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
